<script>
  // 数组方法扩展
  // let arr1 = ['a','b','c','d',5]
  let arr1 = [1, 2, 3, 4, 5]

  // 数组的every方法---返回值为布尔值
  //  数组中所有元素都满足条件 返回true,否则false
  // let res = arr1.every(function (v, i, arr) {
  //   return v>1;
  // })
  // console.log( res )



  // let res = arr1.findIndex(v=>{  // 查找数组中元素的索引，如果不存在则返回-1
  //   return v === 'c';    
  // })
  // console.log(res);

  // let res = arr1.find(v=>{  // find就是查找数组中对应的元素
  //   // 每一个元素执行条件，return true的时候，返回这个元素，并结束遍历
  //   // return v==='6';   
  //   return /\d+/.test(v);
  // })
  // console.log(res);

  // let arr = [{
  //   "goodsId": "3",
  //   "num": "1",
  //   "username": "admin"
  // }, {
  //   "goodsId": "1",
  //   "num": "1",
  //   "username": "admin"
  // }];

  // let username = 'admin',goodsId = 1000;
  // let res1 = arr.findIndex(v=>{
  //   return v.username==username && v.goodsId==goodsId;
  // })
  // console.log(res1);

  // let username = 'admin',goodsId = 1,num = 3;
  // let res = arr.find(v => v.username==username&&v.goodsId==goodsId);
  // console.log(res);
  // console.log(res === arr[1]);  // true
  // // console.log(res.num);
  // res.num = res.num-0+num;
  // console.log(arr);
</script>
<script>
  /* let arr = [
    {"goodsId": "3","num": "1","username": "admin"}, 
    {"goodsId": "1","num": "1","username": "admin"},
    {"goodsId": "1","num": "1","username": "leon"},
  ];

  let username = 'jack';
  let res = arr.map(v=>{
    if(v.username===username){
      return v.goodsId;
    }
  })
  console.log(res); // ["3", "1", undefined]
  // console.log(res.join(','));

  let res2 = res.filter(v=>{
    return v!==undefined;
  })
  console.log(res2); */
</script>